import { _decorator, Component, Node, v3 } from 'cc';
import { EDITOR } from 'cc/env';
const { ccclass, property, menu, executeInEditMode } = _decorator;
declare const CC_EDITOR;

const _v30 = v3();

@ccclass('AlignHelper')
@menu('_mygame/AlignHelper')
@executeInEditMode
export class AlignHelper extends Component {

    @property
    alignPosition: boolean = true;

    @property
    positionStep: number = .05;

    @property
    alignScale: boolean = true;

    @property
    scaleStep: number = .1;

    onLoad() {
        if (!CC_EDITOR) {
            this.destroy();
        }
    }

    update(deltaTime: number) {
        if (EDITOR) {
            _v30.set(this.node.position);
            _v30.x = Math.round(_v30.x / this.positionStep) * this.positionStep;
            _v30.z = Math.round(_v30.z / this.positionStep) * this.positionStep;
            this.node.setPosition(_v30);

            _v30.set(this.node.scale);
            _v30.x = Math.round(_v30.x / this.scaleStep) * this.scaleStep;
            _v30.z = Math.round(_v30.z / this.scaleStep) * this.scaleStep;
            this.node.setScale(_v30);
        }
    }
}


